//
//  CinemaViewController.m
//  UI_豆瓣
//
//  Created by WangZe on 15/10/12.
//  Copyright © 2015年 王泽龙. All rights reserved.
//

#import "CinemaViewController.h"
#import "NetWorkingTool.h"
#import "CinemaList.h"
#import "CinemaListCell.h"
#import "CinemaDetailsViewController.h"
@interface CinemaViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *cinemaArr;

@end

@implementation CinemaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    [_tableView release];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 200;
    self.title = @"影院";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:87 / 255.0 green:137 / 255.0 blue:157 / 255.0 alpha:1];
    [self createData];
    
    
    
    
  
}
- (void)createData
{
    self.cinemaArr = [NSMutableArray array];
    [NetWorkingTool getNetWorking:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/cinemalist.php" block:^(id result) {
        NSDictionary *dic = result;
        NSArray *arr = dic[@"result"][@"data"];
        for (NSDictionary *tempDic in arr) {
            CinemaList *cinema = [[CinemaList alloc] init];
            [cinema setValuesForKeysWithDictionary:tempDic];
            [self.cinemaArr addObject:cinema];
        }
        [self.tableView reloadData];
    
    }];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CinemaDetailsViewController *cinemaDetailsVC = [[CinemaDetailsViewController alloc] init];
    [self.navigationController pushViewController:cinemaDetailsVC animated:YES];
    [cinemaDetailsVC release];
    CinemaList *cinema = self.cinemaArr[indexPath.row];
    NSString *str = [NSString stringWithFormat:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/searchcinema.php?cinemaId=%@", cinema.nameid];
    cinemaDetailsVC.strURL = str;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.cinemaArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse = @"reuse";
    CinemaListCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[CinemaListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
    }
    CinemaList *cinema = self.cinemaArr[indexPath.row];
    cell.upLabel.text = cinema.cinemaName;
    cell.centerLabel.text = cinema.address;
    cell.downLabel.text = cinema.telephone;
    cell.centerLabel.numberOfLines = 2;
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
